package org.example.mybooksystem.config;

import lombok.extern.slf4j.Slf4j;
import org.example.mybooksystem.Modle.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:做渐进主义的改良派,不做完没注意的速成派
 * User: XALEXC
 * Date: 2025-03-18
 * Time: 22:06
 */
@ResponseBody
@Slf4j
@ControllerAdvice
public class ErrorHandler {

    @ExceptionHandler
    public Result except(Exception e) {
        log.error("发生异常,e:{}",e.getMessage());
        return Result.fail("内部错误");
    }

    @ExceptionHandler
    public Result except(NullPointerException e) {
        log.error("发生异常,e:{}",e.getMessage());
        return Result.fail("NullPointerException异常,请联系管理员");
    }

    @ExceptionHandler
    public Result except(ArithmeticException e) {
        log.error("发生异常,e:{}",e.getMessage());
        return Result.fail("ArithmeticException 异常");
    }
}
